package com.ssss.danli;

import com.mbatis.model.User;

import java.io.*;

/**
 * transient 修饰的变量不会参加序列化
 */
public class TransientTest {

    public static void main(String[] args) {
        User user = new User();
        user.setId(1001L);
        user.setUname("zym");

        System.out.println("read before Serializable");
        System.out.println("id:"+user.getId());
        System.out.println("uname:"+user.getUname());
        try{
            ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("D:/zym/user.txt"));
            oos.writeObject(user);
            oos.flush();
            oos.close();
        }catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        
        
        try{
            ObjectInputStream ois = new ObjectInputStream(new FileInputStream("D:/zym/user.txt"));
            user = (User) ois.readObject();
            ois.close();
            System.out.println("\nread after Serializable");
            System.out.println("id："+user.getId());
            System.out.println("name："+user.getUname());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
